package com.example;

 import com.example.entity.User;

 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;

public class UserManager implements UserRepository {
    private Map<String, User> users = new HashMap<>();

    @Override
    public User findByUsername(String username) {
        return users.get(username);
    }

    @Override
    public boolean addUser(User user) {
        if (users.containsKey(user.getUsername())) {
            return false;
        }
        users.put(user.getUsername(), user);
        return true;
    }

    @Override
    public boolean deleteUser(String username) {
        return users.remove(username) != null;
    }

    @Override
    public List<User> getAllUsers() {
        return new ArrayList<>(users.values());
    }

    @Override
    public boolean registerUser(String username, String password, String email, UserRole role) {
        if (users.containsKey(username)) {
            return false;
        }
        User newUser = new User(username, password, email, role);
        users.put(username, newUser);
        return true;
    }
}